/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conexion;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;



/**
 *
 * @author Miguel Pichipillan S
 */
public class Coneccion {
    
    private Connection conexion;
    private Statement estamento;
    
    private String db = "db_bodega";
    private String usuario = "root";
    private String clave = "123456";
    private String servidor = "localhost";
    private String url = "jdbc:mysql://" + this.servidor + "/" + this.db;
    
    
    public Coneccion () {
    }
    
    
   public boolean crearConeccion () {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            this.conexion = DriverManager.getConnection(this.url, this.usuario, this.clave);
            this.estamento = this.conexion.createStatement();
            return true;
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "No se puede inciar la conección\n" + ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
   }
   
   
   public Statement getEstamento () {
       return this.estamento;
   }
   
   public boolean cerrarConeccion () {
        try {
            this.estamento.close();
            this.conexion.close();
            return true;
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "No se puede cerrar la conección \n" + ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
   }
}
